package com.juzipi.inter.domain;

import com.juzipi.inter.pojo.Role;
import com.juzipi.inter.pojo.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginUser implements UserDetails {
    //序列化id
    private static final long serialVersionUID = 1L;

    //用户唯一标识
    private String uuid;
    private String username;
    private String password;
    //登陆时间,用于操作token
    private Long loginTime;
    //过期时间,也是用于操作token
    private Long expireTime;
    //用户的角色列表
    private List<Role> roleList;
    //用户信息
    private User user;


    public LoginUser(User user, List<Role> roleList) {
        this.roleList = roleList;
        this.user = user;
    }

    //权限集合
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }


    //密码
    @Override
    public String getPassword() {
        return user.getPassword();
    }


    //用户名
    @Override
    public String getUsername() {
        return user.getUsername();
    }


    //账号是否未过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }


    //账号是否未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }


    //密码是否未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }


    //是否启用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
